package com.topisv.tms.utils.ttkd;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * 天天快递消息构建工具
 * 
 * @author chenhongtao
 *
 */
public class DayMailMsgBuildUtil {

	/**
	 * 构建运单号段提取
	 * 
	 * @param site
	 *            网点名称
	 * @param cus
	 *            客户名称
	 * @param password
	 *            客户密码
	 * @param getcount
	 *            提取数量
	 * @return
	 */
	public static String buildWayBillMsg(String site, String cus, String password, String getcount,
			String billtype) {
		
		StringBuilder strBuild = new StringBuilder();
		
		strBuild.append("{\"site\":\"");
		strBuild.append(site);
		strBuild.append("\",\"cus\":\"");
		strBuild.append(cus);
		strBuild.append("\",\"password\":\"");
		strBuild.append(password);
		strBuild.append("\",\"getcount\":\"");
		strBuild.append(getcount);
		strBuild.append("\",\"billtype\":\"");
		strBuild.append(billtype);
		strBuild.append("\"");
		strBuild.append("}");

		return strBuild.toString();

	}


	/**
	 * 构建提取大头笔消息体
	 * 
	 * @param site 网点名称
	 * @param cus 客户名称
	 * @param password 客户密码
	 * @return
	 */
	public static String bulidFaceBillMsg(String site, String cus, String password, Map<String, String> dataMap) {

		StringBuilder strBuild = new StringBuilder();
		JSONObject json = JSONObject.fromObject(dataMap);
		strBuild.append("{\"site\":\"");
		strBuild.append(site);
		strBuild.append("\",\"cus\":\"");
		strBuild.append(cus);
		strBuild.append("\",\"password\":\"");
		strBuild.append(password);
		strBuild.append("\",\"data\":[");
		strBuild.append(json);
		strBuild.append("]");
		strBuild.append("}");

		return strBuild.toString();

	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String site = "总部";
		String cus = "测试客户";
		String password = "1234";
		String getcount = "5";
		String billtype = "天天云仓面单";
		String result1 = buildWayBillMsg(site, cus, password, getcount,billtype);
		System.out.println(result1);
		
		Map<String, String> dataMap = new HashMap<String, String>();
		dataMap.put("key","ee");
		dataMap.put("prov","ee");
		dataMap.put("city","ee");
		dataMap.put("area","ee");
		String result2 = bulidFaceBillMsg(site, cus, password, dataMap);
		JSONObject json2 = JSONObject.fromObject(result2);
		System.out.println(result2);
		System.out.println(json2.getString("data"));

		
		List<String> datalist = new ArrayList<String>();
		datalist.add("eee");
		datalist.add("ddd");
		datalist.add("bb");
		JSONArray json = JSONArray.fromObject(datalist);
		System.out.println(json);
		
		List<HashMap<String, String>> dataMaplist = new ArrayList<HashMap<String,String>>();
		dataMaplist.add((HashMap<String, String>) dataMap);
		JSONArray json1 = JSONArray.fromObject(dataMaplist);
		System.out.println(json1);
	}

}
